package com.tgy.algorithm.base.other;

public class _001_最长递增子序列 {

    public static int maxIncreateSubSeq(int[] nums) {

        if (nums == null || nums.length == 0) {
            return 0;
        }

        // 2,4,2,3,4,3,2,
        int len = nums.length;
        int[] lens = new int[len];

        lens[0] = nums[0];
        int left = 0;
        int right = 0;
        int mid,value,location;
        int lenIdx = 0;
        for (int i = 1; i < len; i++) {

            left = 0;
            right = lenIdx;
            value = nums[i];
            location = -1;
            while (left <= right) {
                mid = left + ((right - left) >> 1);
                if (lens[mid] >= value) {
                    location = mid;
                    right = mid - 1;
                }else {
                    left = mid + 1;
                }
            }

            if (location == -1) {
                lens[++lenIdx] = nums[i];
            }else {
                lens[location] = nums[i];
            }
        }

        return lenIdx + 1;
    }

    public static void main(String[] args) {
        int[] nums = {2,4,2,3,4,3,2};
        int maxed = maxIncreateSubSeq(nums);
        System.out.println(maxed);
    }
}
